//
//  BookRequest.m
//  Cbchot
//
//  Created by 李雷川 on 2017/12/4.
//  Copyright © 2017年 王越. All rights reserved.
//

#import "BookInfoRequest.h"
#import "iTools.h"
#import <CBCReader/CBCReader.h>
@interface BookInfoRequest()<RequestBaseDelegate>

/**当前视频对象*/
@property (strong, nonatomic) BookInfo *bookInfo;

@property (nonatomic, strong) NSString *videoId;

@end

@implementation BookInfoRequest
-(void)startRequest:(NSString*)bookID  success:(CAll_BACK) sucuessBack fail:(CAll_BACK) failBack
{
    self.successBack = sucuessBack;
    self.failBack = failBack;
    
    NSString* url = [NSString stringWithFormat:@"%@/api/book/get_book_info/",[iTools ServerHost]];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         bookID ,@"book_id",
                         nil];
    
    [self doPostRequest:url PostBody:dic Delegate:self];
}

/**解析数据*/
-(void)parserData:(NSDictionary *)dic
{
    NSDictionary* bookInfDic = [dic valueForKey:@"bookInfo"];
    self.bookInfo = [[BookInfo alloc]init];
    self.bookInfo.ID = [bookInfDic valueForKey:@"bookId"];
    self.bookInfo.name = [bookInfDic valueForKey:@"bookName"];
    self.bookInfo.author = [bookInfDic valueForKey:@"bookAuthor"];
    self.bookInfo.totalSize = [[bookInfDic valueForKey:@"bookTotalSize"]integerValue];
    self.bookInfo.chapterTotalNum = [[bookInfDic valueForKey:@"bookChapterTotalNum"]integerValue];
    self.bookInfo.detailUrl = [bookInfDic valueForKey:@"bookDetailUrl"];
    self.bookInfo.coverUrl = [bookInfDic valueForKey:@"bookCoverUrl"];
    self.bookInfo.serial = [[bookInfDic valueForKey:@"serial"]boolValue];
    self.bookInfo.introl = [bookInfDic valueForKey:@"bookIntro"];
    self.bookInfo.shareUrl = [bookInfDic valueForKey:@"bookShareUrl"];
}

/*联网解析完成*/
- (void)requestSuccess:(NSString*)message
{
    if(self.successBack){
        self.successBack(self.bookInfo);
    }
}

/*联网失败*/
- (void)requestFailed:(NSString *)errorMessage
{
    if(self.failBack){
        self.failBack(errorMessage);
    }
}


@end
